﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Reports.TurnoverBook
{
    public partial class InputParamForm : Form, IntegrationInterface.IDIProjectForm
    {
        public InputParamForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private string DeptList
        {
            get
            {
                Int32 tmp = (Int32)cbDeparts.SelectedValue;
                if (tmp == -999999)
                    return string.Empty;
                return " AND CO.Departments.Id = " + tmp.ToString() + Environment.NewLine;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Reports.TurnoverBook.DataSet data = new Reports.TurnoverBook.DataSet();
            Reports.TurnoverBook.DataLoader.GetData(data.Data, ConnectionString,this.DeptList, /*Util.Common.DeptName,*/ dtpDateF.Value.Date, dtpDateT.Value.Date.AddDays(1));
            Reports.TurnoverBook.DataSet.InfoRow ir = data.Info.NewInfoRow();
            ir.DateF = dtpDateF.Value.Date.AddSeconds(-1);
            ir.DateT = dtpDateT.Value.Date.AddDays(1).AddSeconds(-1);
            ir.AptekaName = Util.Common.DeptName;
            Util.Data uData = new Reports.Util.Data(this.ConnectionString);
            ir.StartSum = uData.SumFromDateB(ir.DateF, null, null);
            ir.EndSum = uData.SumFromDateE(ir.DateT, null, null);
            ir.RashSum = uData.AllOutput(ir.DateF, ir.DateT, null, null);
            data.Info.Rows.Add(ir);
            PrintForm pf = new PrintForm(data);
            string path = this.CommonProperty as string;
            IntegrationInterface.IDIReport irep = pf as IntegrationInterface.IDIReport;
            irep.InitReport(path);
            pf.MdiParent = this.MdiParent;
            pf.Show();
        }
        #region IDIProjectForm Members
        string _connectionString;
        public string ConnectionString
        {
            get
            {
                return _connectionString;
            }
            set
            {
                _connectionString = value;
            }
        }
        string _login;
        public string Login
        {
            get
            {
                return _login;
            }
            set
            {
                _login = value;
            }
        }

        public Form MailForm
        {
            get
            {
                return this;
            }
        }
        object _obj = null;
        public object CommonProperty
        {
            get
            {
                return _obj;
            }
            set
            {
                _obj = value;
            }
        }

        #endregion        

        private void InputParamForm_Load(object sender, EventArgs e)
        {
            cbDeparts.DataSource = Reports.CommanData.Departs.List(ConnectionString);
        }
    }
}